import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
 *                                if not set alwaysShow, only more than one route under the children
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
 **/
export const constantRoutes = [
  { path: '/login', meta: { go: true }, component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', meta: { go: true }, component: () => import('@/views/404'), hidden: true },

  // {
  //   path: '/acl',
  //   component: Layout,
  //   redirect: '/acl/user/list',
  //   name: '权限管理',
  //   meta: { title: '权限管理', role: ['管理员'] },
  //   children: [
  //     {
  //       path: 'user/list',
  //       name: '用户管理',
  //       component: () => import('@/views/acl/user/list'),
  //       meta: { title: '用户管理' }
  //     },
  //     {
  //       path: 'role/list',
  //       name: '角色管理',
  //       component: () => import('@/views/acl/role/list'),
  //       meta: { title: '角色管理' }
  //     },
  //     {
  //       path: 'role/add',
  //       name: '角色添加',
  //       component: () => import('@/views/acl/role/form'),
  //       meta: { title: '角色添加' },
  //       hidden: true
  //     },
  //     {
  //       path: 'role/update/:id',
  //       name: '角色修改',
  //       component: () => import('@/views/acl/role/form'),
  //       meta: { title: '角色修改' },
  //       hidden: true
  //     },
  //     {
  //       path: 'role/distribution/:id',
  //       name: '角色权限',
  //       component: () => import('@/views/acl/role/roleForm'),
  //       meta: { title: '角色权限' },
  //       hidden: true
  //     },
  //     {
  //       path: 'menu/list',
  //       name: '菜单管理',
  //       component: () => import('@/views/acl/menu/list'),
  //       meta: { title: '菜单管理' }
  //     },
  //     {
  //       path: 'user/add',
  //       name: '用户添加',
  //       component: () => import('@/views/acl/user/form'),
  //       meta: { title: '用户添加' },
  //       hidden: true
  //     },
  //     {
  //       path: 'user/update/:id',
  //       name: '用户修改',
  //       component: () => import('@/views/acl/user/form'),
  //       meta: { title: '用户修改' },
  //       hidden: true
  //     },
  //     {
  //       path: 'user/role/:id',
  //       name: '用户角色',
  //       component: () => import('@/views/acl/user/roleForm'),
  //       meta: { title: '用户角色' },
  //       hidden: true
  //     }
  //   ]
  // },

  // 首页
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: '首页',
    meta: { go: true },
    children: [{
      path: 'index',
      component: () => import('@/views/home/index'),
      meta: { title: '首页', go: true }
    }]
  },
  // 管理
  {
    path: '/manage',
    component: Layout,
    meta: { go: true },
    children: [
      {
        path: 'article',
        name: '内容管理',
        component: () => import('@/views/manage/article'),
        meta: { title: '内容管理' },
        hidden: true
      },
      {
        path: 'problem',
        name: '试题管理',
        component: () => import('@/views/manage/problem'),
        meta: { title: '试题管理' },
        hidden: true
      },
      { path: '*', meta: { go: true }, redirect: '/404', hidden: true }
    ]
  },
  // 博客
  {
    path: '/blog',
    component: Layout,
    meta: { go: true },
    children: [
      {
        path: '',
        name: '博客',
        component: () => import('@/views/blog/index'),
        meta: { title: '博客', go: true }
      },
      {
        path: 'add',
        name: '发布博客',
        component: () => import('@/views/blog/form'),
        meta: { title: '发布博客' },
        hidden: true
      },
      {
        path: ':id',
        name: '博客 ',
        component: () => import('@/views/blog/index'),
        meta: { title: '博客', go: true }
      },
      {
        path: 'edit/:id',
        name: '修改博客',
        component: () => import('@/views/blog/form'),
        meta: { title: '修改博客' },
        hidden: true
      },
      {
        path: 'details/:id',
        name: '博客详情',
        component: () => import('@/views/blog/details'),
        meta: { title: '博客详情', go: true },
        hidden: true
      },
      { path: '*', meta: { go: true }, redirect: '/404', hidden: true }
    ]
  },
  // 试题
  {
    path: '/problem',
    component: Layout,
    meta: { go: true },
    children: [
      {
        path: '',
        name: '试题',
        component: () => import('@/views/problem/index'),
        meta: { title: '试题', go: true }
      },
      {
        path: 'add',
        name: '发布试题',
        component: () => import('@/views/problem/form'),
        meta: { title: '发布试题' },
        hidden: true
      },
      {
        path: 'edit/:id',
        name: '修改试题',
        component: () => import('@/views/problem/form'),
        meta: { title: '修改试题' },
        hidden: true
      },
      {
        path: 'details/:id',
        name: '试题详情',
        component: () => import('@/views/problem/details'),
        meta: { title: '试题详情', go: true },
        hidden: true
      },
      {
        path: 'submission/:id',
        name: '提交记录详情',
        component: () => import('@/views/problem/submission'),
        meta: { title: '提交记录详情', go: true },
        hidden: true
      },
      { path: '*', meta: { go: true }, redirect: '/404', hidden: true }
    ]
  },
  // 个人中心
  {
    path: '/ucenter',
    component: Layout,
    children: [
      {
        path: 'profile',
        name: '个人中心',
        component: () => import('@/views/ucenter/profile'),
        meta: { title: '个人中心' }
      },
      {
        path: 'profile/password',
        name: '密码设置',
        component: () => import('@/views/ucenter/password'),
        meta: { title: '密码设置' },
        hidden: true
      },
      {
        path: 'profile/email',
        name: '邮箱设置',
        component: () => import('@/views/ucenter/email'),
        meta: { title: '邮箱设置' },
        hidden: true
      },
      {
        path: 'profile/phone',
        name: '手机设置',
        component: () => import('@/views/ucenter/phone'),
        meta: { title: '手机设置' },
        hidden: true
      }
    ]
  }

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// export default new Router({
//   // mode: 'history', //后端支持可开
//   scrollBehavior: () => ({ y: 0 }),
//   routes: constantRouterMap
// })

export default router
